
 <template>
 	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap" >
 		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		 <div class="bt">课程编辑</div>
 		<el-form label-width="100px" class="form">
 			
 			<el-form-item label="课程名称">
 				<el-input v-model="form.mc"  placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<el-form-item label="课程分类名称">
 				<el-select v-model="form.flmc" placeholder="请选择课程教材" class="select-block">
							<el-option :label="v.mc" :value="v.mc" v-for="v in comboxlist"></el-option>
						</el-select>
 				<!--<el-input v-model="form.mc"  placeholder="请输入" class="select-block"></el-input>-->
 			</el-form-item>
 			<el-form-item label="课时数量">
 				<el-input v-model="form.ks" type="number"  placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<el-form-item label="课程总价">
 				<el-input v-model="form.jg"  type="number" placeholder="请输入" class="select-block" style='width: 67%;'></el-input>
 				<span style="color: #FD6606;border-bottom: 1px #CCCCCC;">单价：{{jcjg}}</span>
 				<span style="color: red;margin-left: 10px;">注：单位为'元'</span>
 			</el-form-item>
 			<el-form-item label="课程时长">
 				<el-input v-model="form.sc" type="number"  placeholder="请输入" class="select-block" style='width: 67%;'></el-input>
 			    <span style="color: red;">注：单位为分钟</span>
 			</el-form-item>
 			<el-form-item label="满班人数">
 				<el-input v-model="form.mbcns"  type="number" placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<!--<el-form-item label="课程单价">
 				<el-input v-model="jcjg"    :readonly="true" placeholder="请输入" class="select-block" ></el-input>
 			</el-form-item>-->
            <el-form-item label="是否启用">
                <el-select v-model="form.isqy" class="select-block">
                    <el-option label="启用" value="Y"></el-option>
                    <el-option label="禁用" value="N"></el-option>
                </el-select>
 			</el-form-item>
 			<el-form-item label="备注">
 				<el-input v-model="form.note"  type="textarea" :rows="2" placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 		</el-form>
 		<el-button type="primary" class="submit" @click="submit">修改</el-button>
 		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
 	</el-dialog>
 </template>
 <script type="text/javascript">
 	import qs from 'qs'
 	export default {
 		props: ['params'],
 		data() {
 			return {

 				form: {
//					 jcjg :'',
					 ks :'',
					 mbcns:'',
					 zj:'',
                     sc:'',
					 mc :'',
					 isqy :'Y',
					 note :'',
 					id:''
 				},
 				comboxlist:[],
 				
 			}
 		},
 		created() {
  		 this.form.id = this.params.row.id;
          this.loadinfo();
			this.getcomboxlist();
          
 		},
 		methods: {
 			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					xxid: logininfo.xxid,
					yhid: logininfo.id
				})
				//执行
				this.axios.post(this.$store.state.api + 'wpfl/getjc', params2)
					.then(res => {
//						console.log(res,'sssssssssss')
						let data = res.data.data.list;
						let list = data;
						this.comboxlist = list;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
 			loadinfo(){
 			  var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
              var params2 = qs.stringify({
                             xxid:logininfo.xxid,
 							 yhid:logininfo.id,
 							 id:this.form.id
               })
             //执行
                 this.axios.post(this.$store.state.api + 'kcfl/info',  params2 )
                 .then(res => {
                 	console.log(res,'jjj')
                 this.form=res.data.data
                 }).catch(res => {
					this.$message.danger("服务器异常");
 			 		this.$emit('close', { type: 'info', cancel: true });
				})
 			},
 			 submit() {
 				//检测
 				this.$store.state.loading = true;
 				//装载数据
 				var logininfo = JSON.parse(localStorage.logininfo);
 				var params2 = qs.stringify({
 						id: this.form.id,
   						sc: this.form.sc,
 						zj: this.form.jg,
 						ks: this.form.ks,
 						mc: this.form.mc,
 						flmc: this.form.flmc,
 						jcjg:this.jcjg,
 						mbcns: this.form.mbcns,
 						isqy: this.form.isqy,
 						note: this.form.note,
 						yhid: logininfo.id,
 						xxid: logininfo.xxid
 					})
 				//执行
 				    this.axios.post(this.$store.state.api + 'kcfl/update',  params2 )
 						.then(res => {
 							if(res.data.code == 1) {
// 								console.log(res,'jjjjjj')
 								this.$emit('close', { type: 'edit', cancel: false });
 								this.$message.success(res.data.msg);
 								this.$store.state.loading = false;
 							} else {
 							    this.$message.warning(res.data.msg);
 								this.$store.state.loading = false;
 							}
 						}).catch(res => {
	 							this.$message.danger("服务器异常");
	 							this.$store.state.loading = false;
 						})
 			},
 			cancel() {
 				this.$emit('close', { type: 'edit', cancel: true })
 			},
 			
 		},
 		computed: {
		          jcjg(){
		            let number = this.form.jg / this.form.ks;
		            number=number.toFixed(2);
		            if (number<=0) {
		              return 0.00
		            }
		          	return number;
		          },
        	 }
 	}
 </script>
 <style lang="less" scoped>
 	.wrap {
 		text-align: center;
 	}
 	.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top:0;
			left:0;
			background: #50BFFF;
			margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
 	.form {
 		text-align: left;
 		margin-top: 20px;
 	}
 	.input {
             width: 300px;
             display: inline-block;
         }
 	.select-block {
 	}
 	.submit {
 		width: 120px;
 	}
 </style>
